
if($('.middle').html==''){
    $('.empty').display='block';
}else{
    $('.empty').display='none';
}
$(function () {
    $.ajax({
        url:'/car/things',
        type:'post',
        success:function (data) {
            showThings(data);
        },
        error:function (err) {
            console.log('error'+err);
        }
    })
})
function showThings(data) {
    for(var i=0;i<data.length;i++){
        var addDiv=$('<div class="car-div">\n' +
            '                <input type="checkbox" class="checkbox">\n' +
            '                <div class="detail-div">\n' +
            '                <img src="'+data[i].image+'" alt="">\n' +
            '                <p class="title">title:'+data[i].title+'</p>\n' +
            '                <p class="kind">kind:'+data[i].kind+'</p>\n' +
            '                <p class="price">price:'+data[i].price+'</p>\n' +
            '                </div>\n' +
            '                <p><span class="minus">-</span><span class="number">'+data[i].number+'</span><span class="add">+</span>\n' +
            '                </p>\n' +
            '                <span class="total">total:'+data[i].price*data[i].number+'</span>\n' +
            '                <input type="button" class="delete" value="delete" onclick="del(this)">\n' +
            '                <input type="button" class="submit" value="submit">\n' +
            '          </div>');
        $('.middle').append(addDiv);
    }
}
function del(a){
    console.log('ddel');
    var imgsrc=$(a).parent().children().eq(0).html();
    console.log('img',imgsrc);
    $.ajax({
        url:'/car/delete',
        type:'post',
        data:{imgsrc:imgsrc},
        success:function (data){
            showThings(data);
            // location.reload();//页面刷新语句
        },
        error:function (e) {
            console.log('error'+e);
        }
    })
}
$('.add').click(function () {
    $.ajax({
        url:'/car/modify',
        type:'post',
        data:{number:number,imgsrc:imgsrc},
        success:function (data) {
            location.reload();
        },
        error:function (e) {
            console.log('error'+e);
        }
    })
})


